package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.vo.LogErrorInfoVO;
import com.fdb.efp.nls.service.dao.LogErrorInfoDao;
import com.fdb.efp.nls.service.domain.LogErrorInfo;
import com.fdb.efp.nls.service.facade.LogErrorInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 
 * 异常信息表
 * 
 * @author ludayong
 * @since 2019年1月21日 下午9:11:11
 * @version 1.0
 */
@Service("logErrorInfoService")
public class LogErrorInfoServiceImpl implements LogErrorInfoService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(LogErrorInfoServiceImpl.class);

	@Autowired
	private LogErrorInfoDao logErrorInfoDao;

	@Override
	public LogErrorInfoVO queryByApplySeq(LogErrorInfoVO inLogErrorInfoVo) {
		logger.debug("当前查询参数信息为:" + inLogErrorInfoVo);
		try {
			LogErrorInfo queryLogErrorInfo = new LogErrorInfo();
			beanCopy(inLogErrorInfoVo, queryLogErrorInfo);
			LogErrorInfo queryRslLogErrorInfo = logErrorInfoDao.queryByApplySeq(queryLogErrorInfo);
			if (Objects.nonNull(queryRslLogErrorInfo)) {
				LogErrorInfoVO outLogErrorInfoVo = beanCopy(queryRslLogErrorInfo, new LogErrorInfoVO());
				logger.debug("当前查询结果为:" + outLogErrorInfoVo.toString());
				return outLogErrorInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public int updateByCondition(LogErrorInfoVO inLogErrorInfoVo) {
		logger.debug("当前修改数据为:" + inLogErrorInfoVo.toString());
		int num = 0;
		try {
			LogErrorInfo logErrorInfo = new LogErrorInfo();
			beanCopy(inLogErrorInfoVo, logErrorInfo);
			num = logErrorInfoDao.updateByCondition(logErrorInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inLogErrorInfoVo + "修改的数据条数为" + num);
		return num;
	}

	@Override
	public int deleteByApplySeq(LogErrorInfoVO inLogErrorInfoVo) {
		logger.debug("当前删除数据条件为:" + inLogErrorInfoVo);
		int num = 0;
		try {
			LogErrorInfo logErrorInfo = new LogErrorInfo();
			beanCopy(inLogErrorInfoVo, logErrorInfo);
			num = logErrorInfoDao.deleteByApplySeq(logErrorInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inLogErrorInfoVo + "删除的数据条数为" + num);
		return num;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<LogErrorInfoVO> queryAllByCondition(LogErrorInfoVO inLogErrorInfoVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<LogErrorInfoVO> list = null;
		try {
			List<LogErrorInfo> logErrorInfos = logErrorInfoDao.queryAllByCondition(inLogErrorInfoVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + logErrorInfos.size());
			pageSet(logErrorInfos, inLogErrorInfoVo);
			list = (List<LogErrorInfoVO>) beansCopy(logErrorInfos, LogErrorInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	@Override
	public int insertLogErrorInfo(LogErrorInfoVO inLogErrorInfoVo) {
		logger.debug("当前新增数据为:" + inLogErrorInfoVo.toString());
		int num = 0;
		try {
			LogErrorInfo logErrorInfo = new LogErrorInfo();
			beanCopy(inLogErrorInfoVo, logErrorInfo);
			num = logErrorInfoDao.insertLogErrorInfo(logErrorInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	@Override
	public int countByApplySeq(LogErrorInfoVO inLogErrorInfoVo) {
		logger.debug("当前查询参数信息为:" + inLogErrorInfoVo);
		int num = 0;
		try {
			LogErrorInfo logErrorInfo = new LogErrorInfo();
			beanCopy(inLogErrorInfoVo, logErrorInfo);
			num = logErrorInfoDao.countByApplySeq(logErrorInfo);
		} catch (Exception e) {
			logger.error("查询信息发生异常!", e);
			num = -1;
		}
		logger.debug("当前查询条数为:" + num);
		return num;
	}

	@Override
	public int countByApplySeqAndStates(String applySeq, List<String> states) {
		logger.debug("当前查询参数信息为:" + states.toString());
		int num = 0;
		try {
			num = logErrorInfoDao.countByApplySeqAndStates(applySeq, states);
		} catch (Exception e) {
			logger.error("查询信息发生异常!", e);
			num = -1;
		}
		logger.debug("当前查询条数为:" + num);
		return num;
	}

	@Override
	public int updateStateBySernos(Map<String, Object> map) {
		logger.debug("当前查询参数信息为:" + map.toString());
		int num = 0;
		try {
			num = logErrorInfoDao.updateStateBySernos(map);
		} catch (Exception e) {
			logger.error("查询信息发生异常!", e);
			num = -1;
		}
		logger.debug("当前查询条数为:" + num);
		return num;
	}

	@Override
	public List<LogErrorInfoVO> queryByErrorTypeStates(String errorType, List<String> states) {
		logger.debug("当前查询数据信息的参数信息为:");
		List<LogErrorInfoVO> list = null;
		try {
			List<LogErrorInfo> logErrorInfos = logErrorInfoDao.queryByErrorTypeStates(errorType, states);
			logger.debug("当前查询数据信息的结果集数量为:" + logErrorInfos.size());
			list = (List<LogErrorInfoVO>) beansCopy(logErrorInfos, LogErrorInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}
	
	@Override
	public List<LogErrorInfoVO> queryByStates(List<String> states) {
		logger.debug("当前查询数据信息的参数信息为:");
		List<LogErrorInfoVO> list = null;
		try {
			List<LogErrorInfo> logErrorInfos = logErrorInfoDao.queryByStates(states);
			logger.debug("当前查询数据信息的结果集数量为:" + logErrorInfos.size());
			list = (List<LogErrorInfoVO>) beansCopy(logErrorInfos, LogErrorInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}
}
